package schoolword;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class yi {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入文件或目录的路径: ");
        String s = sc.next();
        File file = new File(s);
        if (file.isFile()) {
            System.out.println("文件长度: " + file.length() + "字节");

            //输出文件的修改时间
            System.out.println(new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒").
                    format(new Date(file.lastModified())));

        }else { //若为目录 输出目录中的所有文件  或者子目录
            System.out.println("目录: " + file+", 该目录下的文件或子目录有: ");
            String lists[] = file.list();
            for (int i = 0; i < lists.length; i++) {
                System.out.println("\t" + lists[i]);
            }
        }
    }
}
